This document explains the functions and scripts used for the analysis in the paper
"Modeling the effect of rRNA-mRNA interactions and mRNA folding on mRNA translation in chloroplasts”
by Stav Carmel Ezra and Tamir Tuller.

In order to run the analysis it is recomended to take out all the functions and scripts from the subfolders into a certain directory
from which all the codes will run and all the veriables will be saved.
In every directory there are the functions and scripts necessairy for a certain step in the analysis.
In the following lines there is the explenation for all the functions and scripts for every directory what a, in the chronolgical order that the analysis should run.

Directory : 'gene_banks_chloroplasts':
The chloroplasts' data for the analysis downloases from NCBI.

Directory: 'Chloroplasts data organization codes':

Main script- 'chloroplasts_data_organization.m':
This script loads the chloroplasts' genebanks that were downloaded from NCBI, and for every chloroplast:

1. Creates an organized table of all the information including:
	1.1) The genes sequence, ORF, 5'UTR and 3'UTR - using 'gene_seq.m' function.
	1.2) Protein ID.
	1.3) Gene's name.
	1.4) Strand (primary 1, complimentary -1).
	1.5) The ORF indices at the strand.
	1.6) The genome's name.
	1.7) Locus tag.

2. Extracts the 16S sequence by calling the function 'get_rrn16.m' that uses the following function:
	'get_cell_out_of_struct.m', 'find_cells_with_substring.m', 'extract_seq_by_cordinates.m'.

3. Calculates DCBS, CAI score and Z-scored CAI score for every gene of every chloroplast by using the followong codes:
	'Compute_DCBS.m', 'calculate_CAI.m'.
	Add it to the table of each chloroplast:
	1.8) CAI score.
	1.9) Z-scored CAI score.
	1.10) DCBS score.

Directory: 'Chloroplasts tables':
The chloroplasts tables used in the analysis after running the analysis in Directory 'Chloroplasts data organization codes'.
	
Directory: Orthologues groups:

1. 'create_groups_of_genes_with_same_product.m' script creates groups of genes out of all the chloroplasts that have the same gene product
and filteres the genes in the group such that the remaining genes are similar enough by calling the following functions:

2. 'calculate_graph_by_blast_for_group.m' function calculates BLAST between every couple of genes in the group and filteres the genes in the group.

3. 'Random_CAI.m' script shuffles the Zscored CAI and creates 50 random Z scored CAI vectors for every group. 

4. 'vectorized_chloro_num.m' script creates map vectors of the index of every gene in the group/chloroplast.

Directory: 'Energy based model -ETIP':

Subfolder 'Energies calculations':

1. 'Main_energies_calculations.m': This script calculates all the energies types (mRNA fold, 16S fold, cofold between the mRNA and the 16S), and adds them to the group's table 
by calling the following functions:

2. 'Extract_Features_fold.m' function calculated the fold energy for all the mRNAs of a certain chloroplast in different window sizes at different position at the 5'UTR, it uses the following functions:
	2.1) 'mRNA_fold.m' function calculates the fold energies using viennaRNA fold code.
	2.2) 'create_fold_seq.m' function creates the txt file to insert into viennaRNA fold.

3. 'Extract_16S_fold.m' function calculates the fold energy of the 16S of every chloroplast. 

4. 'Extract_Features_cofold.m' function calculated the co-fold energy for all the mRNAs of a certain chloroplast with the 16S in different window sizes with different position at the 5'UTR, it uses the following functions:
	4.1) 'cofold.m' function calculates the cofold energies using viennaRNA cofold code by calling the following functions:
	4.2) 'cofold_mat_calc.m' function calculates the actuall energies.
	4.2) 'create_cofold_seq.m' function creates the txt file to insert into viennaRNA cofold.

5. 'add_features_to_group.m' function adds the fold and cofold energies features to the group table.

Subfolder Hill climbing:

1. 'Main_hill_climbing.m' script runs the following functions (2-5) to calculate the optimized correlations and parameters for the train set:
 
2. 'hill_fold.m' function finds the optimized correlation and fold energy parameters by hill climbing process.

3. 'hill_cofold.m' function finds the optimized correlation and co-fold energy parameters by hill climbing process.

4. 'hill_ETIP.m' function finds the optimized correlation and ETIP model parameters by hill climbing process.

5. 'create_neighbors.m' functions is used by functions 2,3,4, it that creates the energy neighbors that are checked in the hill climbing process.

6. 'Hill_start_test.m' script runs over all the hill climbing results and saves the best correlation and optimized parameters out of every iteration,
and saves the correlations of the test sets by extracting the optimized energies for every gene in every group according to the optimized parameters, 
by using the function: 

7. 'main_find_optimized_parameters_calc_test.m' finds the optimized parameters and calculates the test correlations by calling the following functions (8,9):

8. 'find_optimized_parameters.m' function finds the optimized parameters for a desired model (fold, co-fold or ETIP) for real and null models.

9. 'create_energy_CAI_corr_test.m' calcluates the energy-CAI correlation for the test set with the optimized parameters.

Subfolder Typical groups and Chlami:

1. 'All_chloro_corrs_and_Chlami_regressor.m' calculates the correlations of the models with the Z-scored CAIs for all the chloroplasts in the database,
 and creates a regressor for Chlamydomonas predicting it's genes protein abundance / ribo-seq values (once with CAI scores, and once with CAI and ETIP values).

2. 'Typical_non_typical_groups_Chlami_Pv.m' divides the groups into typical and non typical groups, calculating the P-values of the genes' PAs of chlamydomonas divided into typical and non typical genes. 

3. 'create_score_matrix_SD_gr.m' calculates the best score and it's position of the SD intercation for every group, and specifically for chlamydomonas genes, and calculates the Pv.

4. 'possible_seq.mat' veriable is all the possible combination of nucleotides A/T/G/C for a sequence length of 5 nt.

5. 'energy_map_SD.mat' veriable is a map of the cofold energy with SD sequence with all the possible sequences.

Directory: 'Groups Structure':

1. 'Predict_structure_group_main.m' predicts the structure of every group by calling the following functions (2,3).
 
2. 'Calculate_MSA_fold_energy_Zscore.m' calculates real and random MSA for every group, calculates the MSA fold aligned to the start codon and to the stop codon, and calculated the Zscore. This function uses the following functions:
 	1.1 'create_fasta.m' - gets the group table and arranges the sequences and headers for the fasta file.
	1.2 'MSA_AA2nt_2num.m' - converts amino acid MSA (ORF) to nucleotides MSA and to numbers MSA (when every amino acid is represented by a different number),
		and converts the nucleotides MSA (3UTR, 5UTR) to numbers MSA (when every number from 1-4 represents a different nucleotide).
	1.3 'MSA_IndelsMap.m' - concatenates the nt MSAs (5UTR+ORF aligned to the start codon , ORF + 3UTR aligned to the stop codon) and the indels map to be able to insert the energies back to the right place in the MSA (the energies are calculated for every gene without the indles of the MSA).
	1.4 'energy_back2indels.m' - inserts the fold energies back to the right place in the MSA.
	1.5 'random_MSA.m' - creates the random MSA by using the following function:
		1.5.1 'columns_permute_ORF_codons.m' - swapping the nucleotides between two columns that have no more than 20% indels.
		1.5.2 'columns_permute_UTR.m' - swapping the codons of the same AAs between two columns of the MSA that are similar in more than 95% of the AAs, and while considering only columns that have no more than 15% indels.
	1.6 'Enrtopy_MSA.m' calculates the entropy of the randomized MSA.

3. 'aliFoldGroup.m' predicts the MSA structure for every group of the positions with significant strong folding (according to the Zscore).

4. 'Zscore_Random.m' creates a random Zscore to find the threshold for significant ratio (positions in the MSA with ratio stronger than the significant ratio are positions that have significant strong fold energy) .


